import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:flutter_todo_2019/page/callback/MyCallback.dart';
import 'package:flutter_todo_2019/page/callback/MySweperCallback.dart';
import 'package:flutter_todo_2019/res/colors.dart';
import 'package:like_button/like_button.dart';

import 'GlobalInfo.dart';

class ItemUtils {
//条目点击
  static Widget getItemView(
      BuildContext context, String text, String mType, MyCallback callback) {
    return new ListTile(
        trailing: Icon(Icons.chevron_right),
        title: Row(
          children: <Widget>[
            Icon(Icons.info, color: Theme.of(context).primaryColor),
            Padding(
              padding: EdgeInsets.only(left: 10.0),
              child: Text(text),
            )
          ],
        ),
        onTap: () {
          callback.onCallback(mType);
        });
  }

  /// 我的页面数据
  static Widget getCardBgView(
      BuildContext context, keyText, mType, MyCallback callback) {
    var itemRowView = new Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
          Opacity(
              opacity: 0.8,
              child: Container(
                  padding: EdgeInsets.fromLTRB(0, 8, 0, 8),
                  child: Text(
                    keyText,
                    style: new TextStyle(fontSize: 14.0, color: Colors.black),
                  ))),
//          IconButton(
//              icon: Icon(
//                Icons.favorite,
//                size: 20.0,
//                color: ThemeUtils.currentThemeColor,
//              ),
//              onPressed: () => callback.onCallback(null))
          LikeButton(size: 25)
        ]);
    return Card(
      //带有圆角，阴影，边框等效果的卡片
      color: Colors.white,
      elevation: 5,
      margin: EdgeInsets.all(15),
      child: Container(
          padding: EdgeInsets.fromLTRB(10, 0, 0, 0), child: itemRowView),
    );
  }

  //水平方向的ItemView
  static Widget getItemCustomView(
      keyText, valueImg, mContext, MyCallback callback) {
    var itemRowView = new Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
          Opacity(
              opacity: 0.8,
              child: Container(
                margin: const EdgeInsets.fromLTRB(15.0, 0, 5.0, 2.0),
                child: Text(
                  keyText,
                  style: new TextStyle(fontSize: 14.0, color: Colors.black),
                ),
              )),
          IconButton(
              icon: Icon(valueImg,
                  size: 24.0, color: Colours.app_mime_value_color),
              onPressed: () => callback.onCallback(null))
        ]);
    return itemRowView;
  }

  static Widget getOpacityText() {
    var view = Opacity(
      opacity: 0.5,
      child: Container(
        width: 100.0,
        height: 100.0,
        margin: EdgeInsets.all(20.0),
        color: Color(0xffff0000),
      ),
    );
    return view;
  }

  static Widget getLinearGradientView() {
    var view = Container(
        width: 10,
        height: 95,
        decoration: BoxDecoration(
            gradient: LinearGradient(
              colors: [Color(0xFFFEC261), Color(0xFFFDE463)],
              begin: Alignment.topCenter,
              end: Alignment.bottomCenter,
            ),
            borderRadius: BorderRadius.only(
                topLeft: Radius.circular(8), bottomLeft: Radius.circular(8))));
    return view;
  }
  /// 轮播图
 static Widget swiperPage(BuildContext context, MySweperCallback callback) {
    return Container(
      height: 190,
      child: Swiper(
        itemBuilder: (BuildContext context, int index) {
          print("index = $index");
          return Container(
            margin: const EdgeInsets.only(top: 16, bottom: 0),
            decoration: BoxDecoration(
                image: DecorationImage(
                  image: AssetImage(GlobalInfo.listImage[index]),
                  fit: BoxFit.cover,
                ),
                borderRadius: BorderRadius.all(Radius.circular(5))),
          );
        },
        autoplayDisableOnInteraction: true,
        itemHeight: 180,
        itemCount: GlobalInfo.listImage.length,
        onTap: (index) {
          callback.onCallback(index);
        },
        viewportFraction: 0.88,
        scale: 0.93,
        outer: true,
        pagination: new SwiperPagination(
          alignment: Alignment.bottomCenter,
          builder: DotSwiperPaginationBuilder(
            activeColor: Colours.textBlack6,
            color: Colours.paginationColor,
            size: 5,
            activeSize: 5,
          ),
        ),
      ),
    );
  }
}
